//============================================================================================
/**
 * @file	phclink_start.c
 * @brief	ＰＨＣ−ＤＳ接続画面 スタート時 【シーケンス】
 * @author	Akito Mori
 * @date	09.01.29
 */
//============================================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/gamedata.h"
#include "system/procsys.h"
#include "system/main.h"
#include "system/fontproc.h"
#include "system/window.h"
#include "system/pmfprint.h"
#include "system/snd_tool.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/clact_tool.h"
#include "system/clact_util.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/mystatus.h"
#include "system/wipe.h"
#include "system/pm_rtc.h"
#include "savedata/config.h"
#include "itemtool/item.h"
#include "itemtool/myitem.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_phc_com.h"

#include "application/phclink.h"
#include "phclink_obj_def.h"
#include "phclink_bmp_def.h"
#include "phclink_local.h"
#include "phclink_obj.h"
#include "phclink_bmp.h"
#include "phc_ds.naix"

//#define  DEBUG_SELECT_PHC

static int SubSeqStart( PHCLINK_WORK *wk );

static int SubSeqWipeWait( PHCLINK_WORK *wk );

static int SubSeqDebugMenu( PHCLINK_WORK *wk );
static int SubSeqDebugMenuWait( PHCLINK_WORK *wk );



static int SubSeqInitMsg( PHCLINK_WORK *wk );
static int SubSeqInitMsgWait( PHCLINK_WORK *wk );
static int SubSeqInit2Msg( PHCLINK_WORK *wk );
static int SubSeqInitSelectInit( PHCLINK_WORK *wk );
static int SubSeqInitSelectWait( PHCLINK_WORK *wk );
static int SubSeqInitSelectAction( PHCLINK_WORK *wk );

static int SubSeqRecvMsg( PHCLINK_WORK *wk );
static int SubSeqRecvMsgWait( PHCLINK_WORK *wk );
static int SubSeqRecvSelectInit( PHCLINK_WORK *wk );
static int SubSeqRecvSelectWait( PHCLINK_WORK *wk );
static int SubSeqRecvSelectAction( PHCLINK_WORK *wk );

static int SubSeqDepositMsg( PHCLINK_WORK *wk );
static int SubSeqDepositMsgWait( PHCLINK_WORK *wk );
static int SubSeqDepositSelectInit( PHCLINK_WORK *wk );
static int SubSeqDepositSelectWait( PHCLINK_WORK *wk );
static int SubSeqDepositSelectAction( PHCLINK_WORK *wk );

static int SubSeqBoxFullMsg( PHCLINK_WORK *wk );
static int SubSeqBoxFullMsgWait( PHCLINK_WORK *wk );
static int SubSeqBoxFullEnd( PHCLINK_WORK *wk );

static int SubSeqBoxNoPokemonMsg( PHCLINK_WORK *wk );


static int SubSeqMsgWait( PHCLINK_WORK *wk );
static int SubSeqCursorAnimeWait( PHCLINK_WORK *wk );
static int SubSeqEnd( PHCLINK_WORK *wk );


static int _first_send_key_check( void );
static int _clear_phc_key_check( void );
static void PhcInitSeqSetup( PHCLINK_WORK *wk, int page_bmp );
static BOOL PhcObligateRecvSetup( PHCLINK_WORK *wk, int page_bmp );
static void UpperScreenSetup( PHCLINK_WORK *wk, int deposit );
static int _get_past_days( PHCLINK_WORK *wk );


//static void _debug_light_birth( PHCLINK_WORK *wk);
//static void _debug_light_move( PHCLINK_WORK *wk);


enum{
	SUBSEQ_START=0,

	SUBSEQ_WIPE_WAIT,			// フェード待ち

	SUBSEQ_DEBUG_MENU,
	SUBSEQ_DEBUG_MENU_WAIT,


	SUBSEQ_INIT_MSG,			// PHC初期登録の流れ
	SUBSEQ_INIT_MSG_WAIT,		// 「ようこそ！
	SUBSEQ_INIT2_MSG,
	SUBSEQ_INIT_SELECT_INIT,	// 選択肢表示
	SUBSEQ_INIT_SELECT_WAIT,	// 選択肢待ち
	SUBSEQ_INIT_SELECT_ACTION,	// 選択結果実行

	SUBSEQ_RECV_MSG,			// PHCから受け取りの流れ
	SUBSEQ_RECV_MSG_WAIT,		// PHCから受け取り
	SUBSEQ_RECV_SELECT_INIT,
	SUBSEQ_RECV_SELECT_WAIT,
	SUBSEQ_RECV_SELECT_ACTION,

	SUBSEQ_DEPOSIT_MSG,			// PHC預け中確認の流れ
	SUBSEQ_DEPOSIT_MSG_WAIT,
	SUBSEQ_DEPOSIT_SELECT_INIT,
	SUBSEQ_DEPOSIT_SELECT_WAIT,
	SUBSEQ_DEPOSIT_SELECT_ACTION,

	SUBSEQ_BOX_FULL_MSG,		// ボックスが5匹以上の空きが無いので
	SUBSEQ_BOX_FULL_MSG_WAIT,	// PHCはできない
	SUBSEQ_BOX_FULL_END,

	SUBSEQ_BOX_NO_POKEMON_MSG,		// ボックスに１匹もいないのでPHCはできない

	SUBSEQ_MSG_WAIT,
	SUBSEQ_CURSOR_ANIME_WAIT,
	SUBSEQ_END,
	SUBSEQ_MAX,
};


static int (*SubSeqFuncTbl[])( PHCLINK_WORK *wk )={
	SubSeqStart,

	SubSeqWipeWait,				// フェード待ち

	SubSeqDebugMenu,
	SubSeqDebugMenuWait,

	SubSeqInitMsg,
	SubSeqInitMsgWait,
	SubSeqInit2Msg,

	SubSeqInitSelectInit,
	SubSeqInitSelectWait,
	SubSeqInitSelectAction,

	SubSeqRecvMsg,
	SubSeqRecvMsgWait,
	SubSeqRecvSelectInit,
	SubSeqRecvSelectWait,
	SubSeqRecvSelectAction,

	SubSeqDepositMsg,
	SubSeqDepositMsgWait,
	SubSeqDepositSelectInit,
	SubSeqDepositSelectWait,
	SubSeqDepositSelectAction,

	SubSeqBoxFullMsg,
	SubSeqBoxFullMsgWait,
	SubSeqBoxFullEnd,

	SubSeqBoxNoPokemonMsg,

	SubSeqMsgWait,
	SubSeqCursorAnimeWait,
	SubSeqEnd,
};


//==============================================================================
/**
 * @brief   PHC処理スタート（現在のDS内PHC状況を確認
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqStart_Init( PHCLINK_WORK *wk )
{
	int i;
	OS_Printf("PhcLink_SeqStart_Init\n");

	OS_Printf("phc-id = ");
	for(i=0;i<40;i++){
		OS_Printf("%x", PhcSvData_GetIdPtr(wk->phc_svdata)[i]);
	}
	OS_Printf("\n");

	// サウンドセット読み込み＆BGM開始
	Snd_DataSetByScene( SND_SCENE_SUB_PHC, SEQ_GS_PHC, 0 );
	Snd_BgmPlay( SEQ_GS_PHC );


	return SEQ_MAINSEQ_MAIN;
}

//==============================================================================
/**
 * @brief   PHCスタート処理メインループ
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqStart_Main( PHCLINK_WORK *wk )
{

	wk->subseq = SubSeqFuncTbl[wk->subseq]( wk );
	if(wk->subseq == SUBSEQ_MAX){
		wk->subseq  = 0;
		return SEQ_MAINSEQ_END;
	}

	return SEQ_MAINSEQ_MAIN;
}

//==============================================================================
/**
 * @brief   PHCスタート処理終了
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqStart_End( PHCLINK_WORK *wk )
{
	OS_Printf("PhcLink_SeqStart_End\n");
	return SEQ_MAINSEQ_INIT;
}



//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================

//------------------------------------------------------------------
/**
 * @brief   テスト用に分岐
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqStart( PHCLINK_WORK *wk )
{
	BOX_DATA *boxdata       = SaveData_GetBoxData( wk->savedata );
	int num;

	WIPE_SYS_Start(
		WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
		WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC, HEAPID_PHC_LINK );

	// ボックスに空きがあるか
	num = BOXDAT_GetEmptySpaceTotal( boxdata );
	if(num < 5){
		// ボックスに5匹以上空きが無いとダメ
		PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
		PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
		return SUBSEQ_BOX_FULL_MSG;

	}

	if( BOXDAT_GetPokeExistCount2Total( boxdata )==0 && PhcSvData_GetPhcDepositNum(wk->phc_svdata)==0 ){
		// ボックスに1匹もポケモンがいないのもダメ
		PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
		PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
		return SUBSEQ_BOX_NO_POKEMON_MSG;

	}

	// 普通の流れ
	{
		u16 flag, box;
		PhcSvData_GetDepositInfo( wk->phc_svdata, &flag, &box );

		switch(flag){
		// PHCと紐つけしてない
		case PHC_NO_PLUG:
			wk->mainseq_next = MAINSEQ_SENDRECV;
			wk->phcsel.monsno = 0;
			wk->subseq_flag   = SENDRECV_SEND;
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			// 非登録状態を偽造
			PhcSvData_SetDepositInfo( wk->phc_svdata, 0 , 0 );
			return SUBSEQ_INIT_MSG;
			break;

		// PHCに預けていない
		case PHC_NO_DEPSIT:
			// PHCに預ける
			wk->phcsel.monsno = 0;
			wk->subseq_flag   = SENDRECV_SEND;
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_H );		// BMPウィンドウ初期化

			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

			UpperScreenSetup( wk, 0 );
			return SUBSEQ_DEPOSIT_MSG;
			break;

		// PHCに預けている
		case PHC_DEPOSIT:
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

			UpperScreenSetup( wk, 1 );

			return SUBSEQ_RECV_MSG;
			break;

		}

	}

	return SUBSEQ_WIPE_WAIT;

}

//----------------------------------------------------------------------------------
/**
 * @brief	上画面情報画面描画
 *
 * @param   wk		PHC画面ワーク
 * @param   no		預けているか?（TRUE, FALSE)
 */
//----------------------------------------------------------------------------------
static void UpperScreenSetup( PHCLINK_WORK *wk, int deposit )
{
	u32 step, wat;
	int next;
	PhcSvData_GetTotalStepWat( wk->phc_svdata, &step, &wat );

	// 歩数とワットをセット
	WORDSET_RegisterNumber( wk->wset,  7,  wat,  7, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	WORDSET_RegisterNumber( wk->wset,  6, step,  7, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );

	next = PhcLink_SearchOpenCourse( wk, wat );
	WORDSET_RegisterNumber( wk->wset, 12, next,  7, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );


	// BG1に文字ウインドウセット
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME1_S, NARC_phc_ds_phcds_win01_u_lz_nscr );
//	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME2_M, NARC_phc_ds_phcds_btn2_d_lz_nscr );
	PhcLink_SetIrcExplainVisible( wk, 1 );
	wk->Bg1SubHOffset = 0;

	// ワット
	PhcLinkBmp_StrPrintColor_S( wk, PL_BMP_A_WALK_TOTAL, wk->WalkTotalStr, FONT_SYSTEM, PHCCOL_T_BLACK );
	PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_WALK_NUM, phc_ds_wcnt, PHCCOL_T_BLACK );

	// 歩数
	PhcLinkBmp_StrPrintColor_S( wk, PL_BMP_A_WAT_TOTAL,  wk->WatTotalStr, FONT_SYSTEM, PHCCOL_T_BLACK );
	PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_WAT_NUM, phc_ds_hcnt, PHCCOL_T_BLACK );

	// 会話ウインドウに次のコースをだすためのワットを表示
	if(next<0){
		// もう全部出た
		PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_TALK, phc_ds_whint02, PHCCOL_T_BLACK );
	}else if(next==0){
		// 今の状態でワットは超えている（あとは預けて引き取ればいいだけ）
		PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_TALK, phc_ds_whint01, PHCCOL_T_BLACK );

	}else{
		// まだワットが足りない(ので目標ワットを表示）
		PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_TALK, phc_ds_whint, PHCCOL_T_BLACK );
	}

	// ポケモンを預けている
	if(deposit){
//		int day = _get_past_days( wk );
		POKEMON_PARAM *pp = PokemonParam_AllocWork(HEAPID_PHC_LINK);
		POKEMON_PASO_PARAM *ppp = PPPPointerGet(pp);
		PhcSvData_GetPokemon(wk->phc_svdata, (u8*)ppp);

		WORDSET_RegisterPokeNickName( wk->wset, 13, ppp );
//		WORDSET_RegisterNumber( 	  wk->wset, 14, day,  3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		PhcLinkBmp_StrPrintExpandColor_S( wk, PL_BMP_A_TRESURE_POKE, phc_ds_poke, PHCCOL_T_WHITE );

		// 正面絵画像転送
		PhcLink_TransPokeGra( ppp, wk->PokeGra, &wk->PokeGraSsa, 1 );

		// 表示ON
		PhcLinkObj_Appear( wk, PLOBJ_ID_POKEMON_U );

		sys_FreeMemoryEz(pp);

	}else{
		// 表示OFF
		PhcLinkObj_Disappear( wk, PLOBJ_ID_POKEMON_U );

		GF_BGL_BmpWinDataFill( &wk->SubBmpWin[PL_BMP_A_TRESURE_POKE], 0 );
		GF_BGL_BmpWinOn( &wk->SubBmpWin[PL_BMP_A_TRESURE_POKE] );
	}

	// PHC本体は隠す
	PhcLinkObj_PhcDisappear( wk );
}

#if 0
static int _get_past_days( PHCLINK_WORK *wk )
{
	// あずけた日を取得
	GF_DATE date   = PhcSvData_GetPhcConnectDate( wk->phc_svdata );
	RTCDate ds_date, now_date;
	int result;

	// GF_DATEをRTCDateに変換
	GFDate2RTCDate( date, &ds_date );

	// 今日を取得
	GF_RTC_GetDate( &now_date );

	// 2000年からの日にちに戻して引き算する
	result = RTC_ConvertDateToDay(&ds_date) - RTC_ConvertDateToDay(&now_date);
	if(result<0){
		result = 0;
	}
	return result;

}
#endif
//----------------------------------------------------------------------------------
/**
 * @brief	 フェードイン待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqWipeWait( PHCLINK_WORK *wk )
{
	if( WIPE_SYS_EndCheck() == TRUE ){
		return SUBSEQ_INIT_MSG;
	}
	return SUBSEQ_DEBUG_MENU;
}


// 地図選択カーソル移動用テーブル
static const course_cur_tbl[]={
	6,7,8,9,10,3,
};


//------------------------------------------------------------------
/**
 * @brief   コース選択処理初期化
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqDebugMenu( PHCLINK_WORK *wk )
{
	int i;
	STRBUF *strbuf;
	PhcLinkBmp_Exit( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
	PhcLinkBmp_Init( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化


	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );

	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME1_S, NARC_phc_ds_phcds_win02_u_lz_nscr );
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME2_M, NARC_phc_ds_phcds_course_d_lz_nscr );

	for(i=0;i<4;i++){
		strbuf = MSGMAN_AllocString( wk->msg_man,
									phc_debug_menu_01+i );
		PhcLinkBmp_StrPrintColor_M( wk, PL_BMP_D_SELECT_0+i, strbuf,
									FONT_TOUCH, PHCCOL_B_BLACK  );
		STRBUF_Delete(strbuf);
	}

	PhcLinkBmp_CancelPrint( wk, PL_BMP_D_CANCEL );			// 「もどる」表示

	// カーソル表示・位置初期化
	wk->cursor_pos = 0;
	PhcLinkObj_CursorPosAppearSet( wk, course_cur_tbl[wk->cursor_pos]);
//	PhcLinkObj_CursorPosAppearSet( wk, 2 );

	return SUBSEQ_DEBUG_MENU_WAIT;
}


//------------------------------------------------------------------
/**
 * @brief   コース選択待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqDebugMenuWait(  PHCLINK_WORK *wk )
{
	if(sys.trg&PAD_KEY_UP){
		if(wk->cursor_pos>0){
			wk->cursor_pos--;
		}
		PhcLinkObj_CursorPosAppearSet( wk, course_cur_tbl[wk->cursor_pos]);

	}else if(sys.trg&PAD_KEY_DOWN){
		if(wk->cursor_pos<5){
			wk->cursor_pos++;
		}
		PhcLinkObj_CursorPosAppearSet( wk, course_cur_tbl[wk->cursor_pos]);
	}else if(sys.trg&PAD_BUTTON_DECIDE){
		switch(wk->cursor_pos){
		case 0:

			// 再度PHCを初期化しますか？
			wk->mainseq_next = MAINSEQ_INITIALIZE;

			// 非登録状態を偽造
			PhcSvData_SetDepositInfo( wk->phc_svdata, 0 , 0 );

			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化

			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			return SUBSEQ_END;

			break;
		case 1:

			// まだ登録していないから登録しますか？
			wk->mainseq_next = MAINSEQ_SENDRECV;
			wk->phcsel.monsno = 0;
			wk->subseq_flag   = SENDRECV_SEND;
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			// 非登録状態を偽造
			PhcSvData_SetDepositInfo( wk->phc_svdata, 0 , 0 );


			return SUBSEQ_INIT_MSG;
			break;
		case 2:
			// PHCに預ける
			PhcSvData_SetDepositInfo( wk->phc_svdata, 1 , 1 );	// 登録済みのふり

			wk->phcsel.monsno = 0;
			wk->subseq_flag   = SENDRECV_SEND;
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_H );		// BMPウィンドウ初期化

			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			return SUBSEQ_DEPOSIT_MSG;

			break;
		case 3:
			// PHCからポケモンを受け取る
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			return SUBSEQ_RECV_MSG;
			break;
		case 4:
			// PHCにポケモンを送信する
			PhcLinkBmp_Exit( wk, PL_BMP_PAGE_D );		// BMPウィンドウ初期化
			PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化
			GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
			GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );
			return SUBSEQ_DEPOSIT_MSG;
			break;
		}


	}
//	_debug_light_birth(wk);
//	_debug_light_move(wk);


	return SUBSEQ_DEBUG_MENU_WAIT;
}




//------------------------------------------------------------------
/**
 * @brief   PHCに初めて登録する（＆ポケモンを送る）
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqInitMsg( PHCLINK_WORK *wk )
{
	// 「ようこそPHCへ！ここではPHCをつかってポケモンと…」
//	wk->MsgIndex = PhcLinkBmp_TalkWinPrint( wk, PL_BMP_B_MINITALK, phc_ds_msg_09 );
	PhcLink_MsgStart( wk, PL_BMP_B_TALK, phc_ds_msg_01, SUBSEQ_INIT2_MSG );

	return SUBSEQ_MSG_WAIT;
}

//------------------------------------------------------------------
/**
 * @brief   メッセージ待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqInitMsgWait( PHCLINK_WORK *wk )
{
	if(GF_MSG_PrintEndCheck( wk->MsgIndex )==0){

		return SUBSEQ_INIT_SELECT_INIT;
	}
	return SUBSEQ_INIT_MSG_WAIT;

}


//----------------------------------------------------------------------------------
/**
 * @brief	 「ポケウォーカーで　ポケモンと　おでかけにいけます」
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqInit2Msg( PHCLINK_WORK *wk )
{
	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

	PhcLink_MsgStart( wk, PL_BMP_B_MINITALK, phc_ds_msg_09, SUBSEQ_INIT_SELECT_INIT );

	return SUBSEQ_MSG_WAIT;
}

//------------------------------------------------------------------
/**
 * @brief   「おでかけにいく」「もどる」選択肢表示
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqInitSelectInit( PHCLINK_WORK *wk )
{
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME2_M, NARC_phc_ds_phcds_btn_d_lz_nscr );

	PhcLinkBmp_StrPrintColor_M( wk, PL_BMP_B_SEL_1, wk->SelectStr[ PL_STRING_FIRST_TANKEN ], FONT_TOUCH, PHCCOL_B_BLACK );
	PhcLinkBmp_CancelPrint( wk, PL_BMP_B_CANCEL );			// 「もどる」表示

	wk->cursor_pos = 0;
	PhcLinkObj_CursorPosAppearSet( wk, 2 );

	return SUBSEQ_INIT_SELECT_WAIT;

}



//------------------------------------------------------------------
/**
 * @brief   初期登録選択肢待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqInitSelectWait( PHCLINK_WORK *wk )
{
	u32 touch = PhcLink_GetTouchTrg( PHC_TOUCH_1_1_MODE );

	// タッチ選択
	if(touch!=RECT_HIT_NONE){
		PhcLink_CursorAnimeStart( wk, touch, 2+touch, SUBSEQ_INIT_SELECT_ACTION );
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		return SUBSEQ_CURSOR_ANIME_WAIT;

	}

	// キー選択
	if(sys.trg&PAD_KEY_UP){
		if(wk->cursor_pos!=0){
			Snd_SePlay(SEQ_SE_DP_SELECT);
		}
		PhcLinkObj_CursorPosAppearSet( wk, 2);
		wk->cursor_pos = 0;
	}else if(sys.trg&PAD_KEY_DOWN){
		if(wk->cursor_pos!=1){
			Snd_SePlay(SEQ_SE_DP_SELECT);
		}
		PhcLinkObj_CursorPosAppearSet( wk, 3);
		wk->cursor_pos = 1;
	}else if(sys.trg&PAD_BUTTON_DECIDE){
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		PhcLink_CursorAnimeStart( wk, wk->cursor_pos, wk->cursor_pos+2, SUBSEQ_INIT_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(sys.trg&PAD_BUTTON_CANCEL){
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		PhcLink_CursorAnimeStart( wk, 1, 3, SUBSEQ_INIT_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(_first_send_key_check()){
		// 完全初期化期登録画面への設定
		Snd_SePlay(SEQ_SE_DP_SELECT);
		PhcInitSeqSetup( wk, PL_BMP_PAGE_D );
		return SUBSEQ_END;
	}else if(_clear_phc_key_check()){
		// 強制送還(預けてなかったら行かない）
		if(PhcObligateRecvSetup( wk, PL_BMP_PAGE_D )){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			return SUBSEQ_END;
		}
	}

	return SUBSEQ_INIT_SELECT_WAIT;

}


//----------------------------------------------------------------------------------
/**
 * @brief	 初期登録選択画面の項目を実行
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqInitSelectAction( PHCLINK_WORK *wk )
{
	PhcLinkObj_CursorDisappear( wk );
	if(wk->cursor_pos==0){
		// 初期登録の流れへ
		wk->mainseq_next = MAINSEQ_SENDRECV;
	}else{
		// 終了
		wk->mainseq_next = MAINSEQ_END_PHC;
	}
	return SUBSEQ_END;

}

//------------------------------------------------------------------
/**
 * @brief   PHCから受け取る画面メッセージ開始
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqRecvMsg( PHCLINK_WORK *wk )
{

//	wk->MsgIndex = PhcLinkBmp_TalkWinPrint( wk, PL_BMP_B_MINITALK, phc_ds_msg_03 );
	PhcLink_MsgStart( wk, PL_BMP_B_MINITALK, phc_ds_msg_03, SUBSEQ_RECV_SELECT_INIT );

	return SUBSEQ_MSG_WAIT;
}


//------------------------------------------------------------------
/**
 * @brief   受け取りメッセージ表示待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqRecvMsgWait( PHCLINK_WORK *wk )
{

	if(GF_MSG_PrintEndCheck( wk->MsgIndex )==0){
		return SUBSEQ_RECV_SELECT_INIT;
	}

	return SUBSEQ_RECV_MSG_WAIT;

}
static const recv_cursor_tbl[]={0,1,3};

//------------------------------------------------------------------
/**
 * @brief   受け取り画面選択肢表示
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqRecvSelectInit( PHCLINK_WORK *wk )
{
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME2_M, NARC_phc_ds_phcds_btn2_d_lz_nscr );
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME1_S, NARC_phc_ds_phcds_win01_u_lz_nscr );

	PhcLinkBmp_StrPrintColor_M( wk, PL_BMP_B_SEL_2_0, wk->SelectStr[ PL_STRING_GET_POKEMON ], FONT_TOUCH, PHCCOL_B_BLACK);
	PhcLinkBmp_StrPrintColor_M( wk, PL_BMP_B_SEL_2_1, wk->SelectStr[ PL_STRING_GET_PRESENT ], FONT_TOUCH, PHCCOL_B_BLACK );
	PhcLinkBmp_CancelPrint( wk, PL_BMP_B_CANCEL );			// 「もどる」表示

	wk->cursor_pos = 0;
	PhcLinkObj_CursorPosAppearSet( wk, recv_cursor_tbl[wk->cursor_pos]);
	return SUBSEQ_RECV_SELECT_WAIT;

}



//------------------------------------------------------------------
/**
 * @brief   受け取り画面選択肢待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqRecvSelectWait( PHCLINK_WORK *wk )
{

	u32 touch = PhcLink_GetTouchTrg( PHC_TOUCH_2_1_MODE );

	if(touch!=RECT_HIT_NONE){
		PhcLink_CursorAnimeStart( wk, touch, recv_cursor_tbl[touch], SUBSEQ_RECV_SELECT_ACTION );
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		return SUBSEQ_CURSOR_ANIME_WAIT;

	}

	if(sys.trg&PAD_KEY_UP){
		if(wk->cursor_pos!=0){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			wk->cursor_pos--;
		}
		PhcLinkObj_CursorPosAppearSet( wk, recv_cursor_tbl[wk->cursor_pos]);
	}else if(sys.trg&PAD_KEY_DOWN){
		if(wk->cursor_pos<2){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			wk->cursor_pos++;
		}
		PhcLinkObj_CursorPosAppearSet( wk, recv_cursor_tbl[wk->cursor_pos]);
	}else if(sys.trg&PAD_BUTTON_DECIDE){
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		PhcLink_CursorAnimeStart( wk, wk->cursor_pos,
								  recv_cursor_tbl[wk->cursor_pos],
								  SUBSEQ_RECV_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(sys.trg&PAD_BUTTON_CANCEL){
		Snd_SePlay(SEQ_SE_DP_SELECT);
		PhcLink_CursorAnimeStart( wk, 2,recv_cursor_tbl[2], SUBSEQ_RECV_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(_first_send_key_check()){
		// 完全初期化期登録画面への設定
		Snd_SePlay(SEQ_SE_DP_SELECT);
		PhcInitSeqSetup( wk, PL_BMP_PAGE_D );
		return SUBSEQ_END;
	}else if(_clear_phc_key_check()){
		// 強制送還(預けてなかったら行かない）
		if(PhcObligateRecvSetup( wk, PL_BMP_PAGE_D )){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			return SUBSEQ_END;
		}
	}

	return SUBSEQ_RECV_SELECT_WAIT;
}


//----------------------------------------------------------------------------------
/**
 * @brief	 受け取り画面選択実行
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqRecvSelectAction( PHCLINK_WORK *wk )
{
	// カーソルオフ
	PhcLinkObj_CursorDisappear( wk );

	// 送信・受信・終了分岐
	switch(wk->cursor_pos){
	case 0:
		wk->mainseq_next = MAINSEQ_SENDRECV;
		wk->subseq_flag  = SENDRECV_RECV;
		break;
	case 1:
		wk->mainseq_next = MAINSEQ_SENDRECV;
		wk->subseq_flag  = SENDRECV_RECV_PRESENT;
		break;
	case 2:
		wk->mainseq_next = MAINSEQ_END_PHC;
		break;
	default:
		GF_ASSERT( wk->cursor_pos<3 );
	}
	return SUBSEQ_END;

}



//----------------------------------------------------------------------------------
/**
 * @brief	 預ける画面メッセージ表示開始
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqDepositMsg( PHCLINK_WORK *wk )
{
//	wk->MsgIndex = PhcLinkBmp_TalkWinPrint( wk, PL_BMP_H_MINITALK, phc_ds_msg_09 );
	PhcLink_MsgStart( wk, PL_BMP_H_MINITALK, phc_ds_msg_09, SUBSEQ_DEPOSIT_SELECT_INIT );


	return SUBSEQ_MSG_WAIT;
}


//----------------------------------------------------------------------------------
/**
 * @brief	 メッセージ表示待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqDepositMsgWait( PHCLINK_WORK *wk )
{
	if(GF_MSG_PrintEndCheck( wk->MsgIndex )==0){
		return SUBSEQ_DEPOSIT_SELECT_INIT;
	}

	return SUBSEQ_DEPOSIT_MSG_WAIT;
}

static const deposit_cursor_tbl[]={11,12,13, 3};

//----------------------------------------------------------------------------------
/**
 * @brief	 預ける選択開始
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqDepositSelectInit( PHCLINK_WORK *wk )
{
	// 3択BG読み込み
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME2_M, NARC_phc_ds_phcds_btn3_d_lz_nscr );
	PhcLink_BgGraphicSet( wk, GF_BGL_FRAME1_S, NARC_phc_ds_phcds_win01_u_lz_nscr );

	PhcLinkBmp_StrPrintColor_M(  wk, PL_BMP_H_SEL_2_0, wk->SelectStr[ PL_STRING_GO_TANKEN   ],
							FONT_TOUCH, PHCCOL_B_BLACK );
	PhcLinkBmp_StrPrintColor_M(  wk, PL_BMP_H_SEL_2_1, wk->SelectStr[ PL_STRING_GET_PRESENT ],
							FONT_TOUCH, PHCCOL_B_BLACK );
	PhcLinkBmp_StrPrintColor_M(  wk, PL_BMP_H_SEL_2_2, wk->SelectStr[ PL_STRING_GET_POKEMON ],
							FONT_TOUCH, PHCCOL_B_BLACK );
	PhcLinkBmp_CancelPrint( wk, PL_BMP_H_CANCEL );

	wk->cursor_pos = 0;
	PhcLinkObj_CursorPosAppearSet( wk, deposit_cursor_tbl[wk->cursor_pos]);

	return SUBSEQ_DEPOSIT_SELECT_WAIT;
}






//------------------------------------------------------------------
/**
 * @brief   「あずける」画面の3択待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//------------------------------------------------------------------
static int SubSeqDepositSelectWait( PHCLINK_WORK *wk )
{
	u32 touch = PhcLink_GetTouchTrg( PHC_TOUCH_3_1_MODE );

	if(touch!=RECT_HIT_NONE){
		PhcLink_CursorAnimeStart( wk, touch,
								  deposit_cursor_tbl[touch],
								  SUBSEQ_DEPOSIT_SELECT_ACTION );
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}

	if(sys.trg&PAD_KEY_UP){
		if(wk->cursor_pos!=0){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			wk->cursor_pos--;
		}
		PhcLinkObj_CursorPosAppearSet( wk, deposit_cursor_tbl[wk->cursor_pos]);
	}else if(sys.trg&PAD_KEY_DOWN){
		if(wk->cursor_pos<3){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			wk->cursor_pos++;
		}
		PhcLinkObj_CursorPosAppearSet( wk, deposit_cursor_tbl[wk->cursor_pos]);
	}else if(sys.trg&PAD_BUTTON_DECIDE){
		Snd_SePlay(SEQ_SE_DP_DECIDE);
		PhcLink_CursorAnimeStart( wk, wk->cursor_pos,
								  deposit_cursor_tbl[wk->cursor_pos],
								  SUBSEQ_DEPOSIT_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(sys.trg&PAD_BUTTON_CANCEL){
		Snd_SePlay(SEQ_SE_DP_SELECT);
		PhcLink_CursorAnimeStart( wk, 3, deposit_cursor_tbl[3], SUBSEQ_DEPOSIT_SELECT_ACTION );
		return SUBSEQ_CURSOR_ANIME_WAIT;
	}else if(_first_send_key_check()){
		// 完全初期化期登録画面への設定
		Snd_SePlay(SEQ_SE_DP_SELECT);
		PhcInitSeqSetup( wk, PL_BMP_PAGE_H );
		return SUBSEQ_END;
	}else if(_clear_phc_key_check()){
		// 強制送還(預けてなかったら行かない）
		if(PhcObligateRecvSetup( wk, PL_BMP_PAGE_D )){
			Snd_SePlay(SEQ_SE_DP_SELECT);
			return SUBSEQ_END;
		}
	}

	return SUBSEQ_DEPOSIT_SELECT_WAIT;

}


//----------------------------------------------------------------------------------
/**
 * @brief	 「預ける」選択肢、決定項目実行
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqDepositSelectAction( PHCLINK_WORK *wk )
{
	// カーソルオフ
	PhcLinkObj_CursorDisappear( wk );


	// 「送信・受信・プレゼント受信・やめる」分岐
	switch(wk->cursor_pos){
	case 0:
		// 預ける
		wk->mainseq_next = MAINSEQ_SENDRECV;
		wk->subseq_flag  = SENDRECV_SEND;
		break;
	case 1:
		// 引き取る
		wk->mainseq_next = MAINSEQ_SENDRECV;
		wk->subseq_flag  = SENDRECV_RECV;
		break;
	case 2:
		// プレゼント受け取り
		wk->mainseq_next = MAINSEQ_SENDRECV;
		wk->subseq_flag  = SENDRECV_RECV_PRESENT;
		break;
	case 3:
		// やめる
		wk->mainseq_next = MAINSEQ_END_PHC;
		break;
	default:
		GF_ASSERT( wk->cursor_pos<4 );
	}
	return SUBSEQ_END;

}

//----------------------------------------------------------------------------------
/**
 * @brief	 ボックスがいっぱいメッセージ
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqBoxFullMsg( PHCLINK_WORK *wk )
{

	PhcLinkObj_CursorDisappear( wk );
	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME2_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME2_M );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

	// メッセージ表示開始
	PhcLink_MsgStart( wk,  PL_BMP_B_TALK, phc_ds_msg_16, SUBSEQ_BOX_FULL_END );

	return SUBSEQ_MSG_WAIT;
}


//----------------------------------------------------------------------------------
/**
 * @brief	 ボックスメッセージ終了待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqBoxFullMsgWait( PHCLINK_WORK *wk )
{
	if(GF_MSG_PrintEndCheck( wk->MsgIndex )==0){
		wk->mainseq_next = MAINSEQ_END_PHC;
		return SUBSEQ_END;
	}
	return SUBSEQ_BOX_FULL_MSG_WAIT;
}


//----------------------------------------------------------------------------------
/**
 * @brief	 ボックス一杯なので終了
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqBoxFullEnd( PHCLINK_WORK *wk )
{
	wk->mainseq_next = MAINSEQ_END_PHC;
	return SUBSEQ_END;
}



//----------------------------------------------------------------------------------
/**
 * @brief	 ボックスがいっぱいメッセージ
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqBoxNoPokemonMsg( PHCLINK_WORK *wk )
{

	PhcLinkObj_CursorDisappear( wk );
	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME2_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME2_M );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

	// メッセージ表示開始
	PhcLink_MsgStart( wk,  PL_BMP_B_TALK, phc_ds_msg_23, SUBSEQ_BOX_FULL_END );

	return SUBSEQ_MSG_WAIT;
}


//----------------------------------------------------------------------------------
/**
 * @brief	 会話ウインドウ表示終了待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqMsgWait( PHCLINK_WORK *wk )
{
	if(GF_MSG_PrintEndCheck( wk->MsgIndex )==0){
//		wk->mainseq_next = MAINSEQ_END_PHC;
//		return SUBSEQ_END;
		wk->subseq = wk->subseq_next;
		return wk->subseq;
	}
	return SUBSEQ_MSG_WAIT;

}


//----------------------------------------------------------------------------------
/**
 * @brief	 カーソルアニメ待ち
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqCursorAnimeWait( PHCLINK_WORK *wk )
{
	if(CATS_ObjectAnimeActiveCheckCap( wk->cap[PLOBJ_ID_CURSOR])==FALSE){
		wk->subseq = wk->subseq_next;
		return wk->subseq;
	}
	return SUBSEQ_CURSOR_ANIME_WAIT;

}

//----------------------------------------------------------------------------------
/**
 * @brief	 アプリ内シーケンス最終地点
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  int	サブシーケンス
 */
//----------------------------------------------------------------------------------
static int SubSeqEnd( PHCLINK_WORK *wk )
{
	return SUBSEQ_MAX;
}



//----------------------------------------------------------------------------------
/**
 * @brief	 完全初期化へ行く設定
 *
 * @param   wk
 */
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
/**
 * @brief	 完全初期化へ行く設定
 *
 * @param   wk			PHC画面ワーク
 * @param   page_bmp	ページBMP設定番号（PAGE_BMP_A　〜
 */
//----------------------------------------------------------------------------------
static void PhcInitSeqSetup( PHCLINK_WORK *wk, int page_bmp )
{
	// 再度PHCを初期化しますか？
	wk->mainseq_next = MAINSEQ_INITIALIZE;

	PhcLinkBmp_Exit( wk, page_bmp );			// BMPウィンドウ解放
	PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化

	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

	// カーソル消去
	PhcLinkObj_CursorDisappear( wk );
}

//----------------------------------------------------------------------------------
/**
 * @brief	強制変換へ行く設定
 *
 * @param   wk
 */
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
/**
 * @brief	強制変換へ行く設定
 *
 * @param   wk			PHC画面ワーク
 * @param   page_bmp	BMPページ設定番号
 *
 * @retval  BOOL		TRUE:預けてる	FALSE:預けてない
 */
//----------------------------------------------------------------------------------
static BOOL PhcObligateRecvSetup( PHCLINK_WORK *wk, int page_bmp )
{
	u16 flag, box;

	// ポケモンを預けていない場合は無視
	PhcSvData_GetDepositInfo( wk->phc_svdata, &flag, &box );
	if(flag!=PHC_DEPOSIT){
		return FALSE;
	}

	// 強制送還画面へ
	wk->mainseq_next = MAINSEQ_SENDRECV;
	wk->subseq_flag  = RECVDEMO_OBLIGATE_RECV;

	PhcLinkBmp_Exit( wk, page_bmp );		// BMPウィンドウ初期化
	PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ初期化

	GF_BGL_ScrFill(	wk->bgl, GF_BGL_FRAME1_M, 0x0000, 0, 0, 32, 24, GF_BGL_SCRWRT_PALNL );
	GF_BGL_LoadScreenReq( wk->bgl, GF_BGL_FRAME1_M );

	// カーソル消去
	PhcLinkObj_CursorDisappear( wk );

	return TRUE;
}


//=============================================================================================
/**
 * @brief	 初期登録画面へ行くキー操作チェック
 *
 * @param   none
 *
 * @retval  int		1:入力あった	0:入力無し
 */
//=============================================================================================
static int _first_send_key_check( void )
{
	if((sys.cont&PAD_KEY_DOWN)&&(sys.cont&PAD_BUTTON_X)&&(sys.cont&PAD_BUTTON_L)){
		return 1;
	}
	return 0;
}


//=============================================================================================
/**
 * @brief	 ＰＨＣ完全初期化へ行くキー操作チェック
 *
 * @param   none
 *
 * @retval  int		1:入力あった	0:入力無し
 */
//=============================================================================================
static int _clear_phc_key_check( void )
{
	if((sys.cont&PAD_KEY_UP)&&(sys.cont&PAD_BUTTON_SELECT)&&(sys.cont&PAD_BUTTON_R)){
		return 1;
	}
	return 0;
}